<style tyle="text/css">
  #aaa a:hover {
    text-decoration: underline;
    color: #0A8CD1;
  }
</style>
<div class="wrapper-md ng-scope">
  <div class="row">

    <div class="panel panel-default">
      <tabset class="tab-container" >

        <tab heading="机构列表" active="status.active" ng-click="cancel()">
          <div class="panel-body" ng-if="status.tree">
            <table id="treetable" class="table table-striped table-bordered dataTable table-condensed tree_table" style="display: none;">
              <thead>
                <tr>
                  <th style="width: 13%;text-align:center;">机构名称</th>
                  <th style="width: 4%;text-align:center;">归属区域</th>
                  <th style="width: 5%;text-align:center;">机构编码</th>
                  <th style="width: 3%;text-align:center;">类型</th>
                  <th style="width: 9%;text-align:center;">操作</th>
                </tr>
              </thead>
              <tbody>
                <tr ng-repeat="office in office_list" id="{{office.id}}" pid="{{office.parent_id}}" sort="{{office.sort}}" officeloadover>
                  <td style="padding: 8px 5px"><a href ng-click="update(office)" style="color:#2fa4e7">{{office.name}}</a></td>
                  <td style="text-align:center;">{{office.area_name}}</td>
                  <td style="text-align:center;">{{office.code}}</td>
                  <td style="text-align:center;">{{office.type_c}}</td>
                  <td style="padding: 8px 5px" align="center">
                    <div ng-if="office.flag == 1">
                      <button type="button" class="btn btn-info btn-xs" ng-click="add(office)">添加下级</button>
                      <button type="button" class="btn btn-info btn-xs" ng-click="bindInfo(office)">绑定信息</button>
                      <button type="button" class="btn btn-info btn-xs" ng-click="update(office)">修改</button>
                      <button type="button" class="btn btn-danger btn-xs" ng-click="delete(office)">删除</button>
                      <button type="button" class="btn btn-info btn-xs" ng-click="createRelation(office)">分销商</button>
                    </div>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>

          <div class="row wrapper" ng-if="!status.tree">
            <div class="col-sm-8">
              <h4 class="col-sm-12 control-label" id="aaa">{{parentOffice[parentsLength].name}} : 
                <label ng-repeat="info in parentOffice">
                  <a style="color:#2fa4e7" ng-click="selectParent($index)">{{info.code}}</a>/
                </label>
              </h4>
            </div>
            <div class="col-sm-4 pull-right">
              <div class="col-sm-7 m-b-xs">
                <input type="text" class="form-control" ng-model="searchform.name" placeholder="机构名称">
              </div>
              <button class="btn m-b-xs w-xs btn-success" ng-click="searchData()">搜索</button>
            </div>
          </div>
          <div class="panel-body" ng-if="!status.tree">
            <table class="table table-striped table-bordered dataTable table-condensed tree_table">
              <thead>
                <tr>
                  <th style="width: 12%;text-align:center;">机构名称</th>
                  <th style="width: 4%;text-align:center;">归属区域</th>
                  <th style="width: 5%;text-align:center;">机构编码</th>
                  <th style="width: 3%;text-align:center;">类型</th>
                  <th style="width: 10%;text-align:center;">操作</th>
                </tr>
              </thead>
              <tbody>
                <tr ng-repeat="office in office_list">
                  <td style="padding: 8px 5px"><a href ng-click="update(office)" style="color:#2fa4e7">{{office.name}}</a></td>
                  <td style="text-align:center;">{{office.area_name}}</td>
                  <td style="text-align:center;">{{office.code}}</td>
                  <td style="text-align:center;">{{office.type_c}}</td>
                  <td style="padding: 8px 5px">
                    <div ng-if="status.office_flag == '1' ">
                      <button type="button" class="btn btn-info btn-xs" ng-click="add(office)">添加下级</button>
                      <button type="button" ng-if="office.childnum > 0" class="btn btn-info btn-xs" ng-click="selectDown(office)">查看下级</button>
                      <button type="button" class="btn btn-info btn-xs" ng-click="bindInfo(office)">绑定信息</button>
                      <button type="button" class="btn btn-info btn-xs" ng-click="update(office)">修改</button>
                      <button type="button" class="btn btn-danger btn-xs" ng-click="delete(office)">删除</button>
                    </div>
                  </td>
                </tr>
              </tbody>
            </table>
            <div class="text-right" style="background-color: white">
              <pagination total-items="page.totalItems" ng-model="page.currentPage" ng-change="searchData()" previous-text="上一页"
                next-text="下一页" first-text="首页" last-text="尾页" max-size="5" boundary-links="true" rotate="false"
                items-per-page="page.pageSize" class="pagination pagination-sm m-t-none m-b-none"></pagination>
            </div>
          </div>
        </tab>

        <tab heading={{tabname.name}} ng-click="add(office_list[0],0)" active="tabname.active">
          <div class="panel-body">
            <form name="form1" class="form-horizontal ng-pristine ng-valid-required">
              <div class="form-group" ng-if="obj.addSub">
                <label class="col-lg-2 control-label">上级机构:</label>
                <div class="col-lg-4">
                  <input type="text" class="form-control" ng-model="obj.super_name" ng-disabled="true">
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">机构名称:</label>
                <div class="col-lg-4">
                  <input type="text" class="form-control" ng-model="obj.name" placeholder='必填'>
                </div>
              </div>
              <div class="form-group" ng-if="status.code_flag">
                <label class="col-lg-2 control-label">机构编号:</label>
                <div class="col-lg-4">
                  <input type="text" class="form-control" ng-model="obj.code" placeholder='必填、唯一'>
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">运营商编号:</label>
                <div class="col-lg-4">
                  <ui-select ng-model="obj.sys_area" ng-disabled="status.flag" theme="bootstrap">
                    <ui-select-match placeholder="选择...">{{$select.selected.label}}</ui-select-match>
                    <ui-select-choices repeat="item.value as item in sys_area_list | filter: $select.search">
                      <span ng-bind-html="item.label"></span>
                    </ui-select-choices>
                  </ui-select>
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">归属区域:</label>
                <div class="col-lg-4">
                  <ui-select ng-model="obj.area_id" theme="bootstrap">
                    <ui-select-match placeholder="选择区域..">{{$select.selected.name}}</ui-select-match>
                    <ui-select-choices repeat="item.id as item in cityList | filter: $select.search">
                      <span ng-bind-html="item.name | highlight: $select.search"></span>
                    </ui-select-choices>
                  </ui-select>
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">机构类型:</label>
                <div class="col-lg-4">
                  <select ng-model="obj.type" class="form-control" ng-disabled="true">
                    <option value="1">公司</option>
                    <option value="2">部门</option>
                    <option value="3">小组</option>
                    <option value="4">其他</option>
                  </select>
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">机构等级:</label>
                <div class="col-lg-4">
                  <select ng-model="obj.grade" class="form-control" ng-disabled="true">
                    <option value="1">一级</option>
                    <option value="2">二级</option>
                    <option value="3">三级</option>
                    <option value="4">四级</option>
                    <option value="5">五级</option>
                    <option value="6">六级</option>
                    <option value="7">七级</option>
                    <option value="8">八级</option>
                    <option value="9">九级</option>
                  </select>
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">是否启用:</label>
                <div class="col-lg-4">
                  <label class="i-switch m-t-xs m-r">
                    <input type="checkbox" ng-true-value="'1'" ng-false-value="'0'" ng-model="obj.USEABLE">
                    <i></i>
                  </label>
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">联系地址:</label>
                <div class="col-lg-4">
                  <input type="text" class="form-control" ng-model="obj.address">
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">邮政编码:</label>
                <div class="col-lg-4">
                  <input type="text" class="form-control"  ng-model="obj.zip_code">
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">电话:</label>
                <div class="col-lg-4">
                  <input type="text" class="form-control" ng-model="obj.phone">
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">传真:</label>
                <div class="col-lg-4">
                  <input type="text" class="form-control" ng-model="obj.fax">
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">邮箱:</label>
                <div class="col-lg-4">
                  <input type="text" class="form-control" ng-model="obj.email">
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">负责人:</label>
                <div class="col-lg-4">
                  <input type="text" class="form-control" ng-model="obj.master">
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">主负责人:</label>
                <div class="col-lg-4">
                  <input type="text" class="form-control" ng-model="obj.PRIMARY_PERSON">
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">副负责人:</label>
                <div class="col-lg-4">
                  <input type="text" class="form-control" ng-model="obj.DEPUTY_PERSON">
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">排序:</label>
                <div class="col-lg-4">
                  <input type="number" class="form-control" ng-model="obj.sort">
                </div>
              </div>
              <div class="form-group">
                <label class="col-lg-2 control-label">备注信息:</label>
                <div class="col-lg-4">
                  <textarea class="form-control" rows="3" ng-model="obj.remarks"></textarea>
                </div>
              </div>
              <div class="form-group" ng-if="tabname.name != '修改机构'">
                <label class="col-lg-2 control-label"></label>
                <div class="col-lg-8">
                  <input type="checkbox" ng-model="obj.set_user" ng-change="sel()" class="ng-valid ng-dirty ng-valid-parse ng-touched">
                  <i>勾选之后，会自动添加同名的用户。用户初始密码:000000，请尽快修改密码。</i>
                </div>
              </div>
              <div class="form-group" ng-if="obj.set_user">
                <label class="col-lg-2 control-label">* 用户角色:</label>
                <div class="col-lg-7">
                  <label ng-repeat="info in role_list" style="margin-bottom:2px; margin-right:2px; width:116px" 
                  class="btn btn-xs btn-default" ng-model="info.active" btn-checkbox="">
                      <span class="text">{{info.name}}</span>
                      <i class="fa fa-check text-active"></i>
                      <span class="text-active">{{info.name}}</span>    
                  </label>
                </div>
              </div>
            </form>
            <div class="col-lg-2"></div>
            <div class="col-lg-4">
              <button class="btn btn-primary btn-rounded" ng-click="save()">保存</button>
              <button class="btn btn-default btn-rounded" ng-click="cancel()">取消</button>
            </div>
          </div>
        </tab>



      </tabset>
    </div>

  </div>
</div>


